const router = require("koa-router")();
const axios = require("axios");

//开启nacos
router.prefix("/ysms-dlearn-web");

router.get("/", function(ctx, next) {
    ctx.body = "this is a users response!";
});

// router.get('/', async (ctx, next) => {
//   await ctx.render('index', {
//     title: 'Hello Koa 2!'
//   })
// })

router.get("/string", async (ctx, next) => {
    ctx.body = "koa2 string";
});

router.get("/json", async (ctx, next) => {
    ctx.body = {
        title: "koa2 json"
    };
});

router.post("/postPythonScript", async function(ctx, next) {
    const REQUEST_PARAMS = ctx.request.body;
    const RESULT = await axios.post(REQUEST_PARAMS.url, REQUEST_PARAMS.params);
    ctx.response.body = JSON.stringify(RESULT.data);
});

module.exports = router;
